home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Screen Rotator / CPatchMakerINIT / Patches.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.3 KB  |  117 lines

  1. // Source Code generated by PatchMaker 1.1
  2. // a sick idea by Paul Baxter
  3. //
  4. // paul@paulbaxter.com
  5. // ProcInfo for additional traps by Matthew Dolan
  6.  
  7. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  8.     #error Sorry Can't do that
  9. #endif
  10.  
  11. #include <MixedMode.h>
  12. #include <Appearance.h>
  13. #include <SpeechSynthesis.h>
  14. #include <A4Stuff.h>
  15.  
  16. // enums for routinedescriptor
  17. enum {
  18.     uppOffsetRectProcInfo = kPascalStackBased
  19.         |    STACK_ROUTINE_PARAMETER(1,kFourByteCode)
  20.         |    STACK_ROUTINE_PARAMETER(2,kTwoByteCode)
  21.         |    STACK_ROUTINE_PARAMETER(3,kTwoByteCode),
  22.     uppPatchExtraInfo    // not used
  23. };
  24.  
  25. // Function Prototypes
  26. extern pascal void myOffsetRectPatch(long param1, short param2, short param3);
  27.  
  28.  
  29. // Globals to hold original routine descriptors
  30. RoutineDescriptorPtr gOriginalOffsetRect = nil;
  31.  
  32.  
  33. // Tell MetroWerks the procInfo for main
  34. ProcInfoType __procinfo =  kPascalStackBased;
  35. pascal void main(void)
  36. {
  37.     RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
  38.     UInt32 size;
  39.     UInt16 index;
  40.     THz theZone;
  41.  
  42.     // get globals
  43.     EnterCodeResource();
  44.     // detach ourselves
  45.     DetachResource(Get1Resource('INIT', 0));
  46.  
  47.     // make sure we are in the system heap
  48.     theZone = GetZone();
  49.     SetZone(SystemZone());
  50.     
  51.     unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
  52.  
  53.     originaldesc = NGetTrapAddress(_OffsetRect, (OffsetRect & 0x0800) ? ToolTrap : OSTrap);
  54.     if (originaldesc != unImplimentedTrapAddr) {
  55.         if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
  56.             // Trap is 68K
  57.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
  58.             // allocate new descriptor
  59.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  60.             if (!newdesc) {
  61.                 Debugger();
  62.                 return;
  63.             }
  64.             // set fields of routine decscriptor
  65.             newdesc->goMixedModeTrap = _MixedModeMagic;
  66.             newdesc->version = 7;
  67.             newdesc->routineDescriptorFlags = 0;
  68.             newdesc->reserved1 = 0;
  69.             newdesc->reserved2 = 0;
  70.             newdesc->selectorInfo = 0;
  71.             newdesc->routineCount = 0;
  72.             index = 0;
  73.             gOriginalOffsetRect = originaldesc;
  74.             newdesc->routineRecords[index].procInfo = uppOffsetRectProcInfo;
  75.             newdesc->routineRecords[index].reserved1 = 0;
  76.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  77.             newdesc->routineRecords[index].routineFlags = 4;
  78.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)myOffsetRectPatch;
  79.             newdesc->routineRecords[index].reserved2 = 0;
  80.             newdesc->routineRecords[index].selector = 0;
  81.         }
  82.         else {
  83.             // Trap is PPC
  84.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
  85.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  86.             if (!newdesc) {
  87.                 DebugStr("\pFailed to allocate RoutineDescriptor");
  88.                 return;
  89.             }
  90.             BlockMoveData(originaldesc, newdesc, size);
  91.             gOriginalOffsetRect = originaldesc;
  92.             index = 0;
  93.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)myOffsetRectPatch;
  94.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  95.         }
  96.         NSetTrapAddress((UniversalProcPtr) newdesc, OffsetRect, (OffsetRect & 0x0800) ? ToolTrap : OSTrap);
  97.     }
  98.  
  99.     // restore to original heap
  100.     SetZone(theZone);
  101.     // restore globals
  102.     ExitCodeResource();
  103. }
  104.  
  105.  
  106. pascal void myOffsetRectPatch(long param1, short param2, short param3)
  107. {
  108.     // Get globals
  109.     EnterCodeResource();
  110.  
  111.     CALL_THREE_PARAMETER_UPP( gOriginalOffsetRect, uppOffsetRectProcInfo, param1, param2, param3);
  112.  
  113.     // Release globals
  114.     ExitCodeResource();
  115. }
  116.  
  117.